@extends('admin.main')
@section('content')
    <div class="daohang">
        <ul>
            <li>
                <button type="button" class="am-btn am-btn-default am-radius am-btn-xs"> 科室管理</button>
            </li>
        </ul>
    </div>
    <div class="admin-biaogelist">

        <div class="listbiaoti am-cf">
            <ul class="am-icon-flag on"> 科室列表</ul>
            <dl>
                <button type="button" class="am-btn am-btn-danger am-round am-btn-xs am-icon-plus"
                        onclick="window.location.href='{{urlAdmin('depart','getAdd')}}'"> 添加科室
                </button>
            </dl>
            <!--这里打开的是新页面-->
        </div>
        <form class="am-form am-g">
            <table width="100%" class="am-table am-table-bordered am-table-radius am-table-striped am-table-hover">
                <thead>
                <tr class="am-success">
                    <th class="table-check"><input type="checkbox"/></th>
                    <th class="table-id">ID</th>
                    <th class="table-title">科室名称</th>
                    <th class="table-date am-hide-sm-only">添加日期</th>
                    <th width="150px" class="table-set">操作</th>
                </tr>
                </thead>
                <tbody>
                @if(!empty($rows))
                    @foreach($rows as $v)
                        <tr id="tr_{{$v['id']}}">
                            <td><input type="checkbox"/></td>
                            <td>{{$v['id']}}</td>
                            <td>{{$v['name']}}</td>
                            <td class="am-hide-sm-only">{{$v['created_at']}}</td>
                            <td>
                                <a href="{{urlAdmin("depart",'getEdit',['id'=>$v['id']],2)}}"class="abtn">编辑</a>
                                <a href="javascript:void(0)" onclick="del({{$v['id']}})" class="abtn ff6600">删除</a>
                            </td>
                        </tr>
                    @endforeach
                @else
                    <tr>
                        <td colspan="3" style="text-align: center"><span>暂无数据~</span></td>

                    </tr>
                @endif
                </tbody>
            </table>
            @if(!empty($rows['pageNoList']))
                <ul class="am-pagination am-fr">
                    <li @if(!$rows['prev_page_url']) class="am-disabled" @endif ><a
                                href="{{$rows['prev_page_url']}}">«</a></li>
                    @foreach($res['pageNoList'] as $v)
                        <li @if($rows['current_page'] == $v) class="am-active" @endif><a
                                    href="{{urlAdmin('depart','getIndex',['page'=>$v],2)}}">{{$v}}</a></li>
                    @endforeach
                    <li @if(!$rows['next_page_url']) class="am-disabled" @endif><a
                                href="{{$rows['next_page_url']}}">»</a></li>
                </ul>
            @endif
            <hr/>
        </form>
        @include('admin.footer')
    </div>
@section('script')
    <script>
        function del(id) {
            layer.confirm('您确定要删除吗？', {
                btn: ['确定', '取消'] //按钮
            }, function () {
                $.ajax({
                    type: "get",
                    url: "{{urlAdmin('depart','getDel')}}?id=" + id,
                    dataType: "json",
                    success: function (res) {
                        if (res['status'] == 1) {
                            layer.msg('删除成功', {icon: 6}, function () {
                                $('#tr_'+id).hide();
                            });
                        } else {
                            layer.msg('删除失败', {icon: 5});
                        }
                    }
                })
            });
        }
    </script>
@endsection
@endsection